//
//  HTClassDesCell.swift
//  QuitSmokingApp
//  
//  Created by wealon on 2024.
//  QuitSmokingApp.
//  
    

import UIKit

class HTClassDesCell: UITableViewCell {

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    var BLOCK_premiumBLOCK: (() -> Void)?
    var BLOCK_webClickBLOCK: ((String) -> Void)?
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.contentView.backgroundColor = .clear
        self.backgroundColor = .clear
        self.selectionStyle = .none
        ht_setUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    func ht_setUI() {
        let var_contentView = UIView()
        var_contentView.layer.cornerRadius = 4.auto()
        var_contentView.layer.borderWidth = 1
        var_contentView.layer.borderColor = UIColor("#298CB2").cgColor
        contentView.addSubview(var_contentView)
        var_contentView.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(30)
            make.left.equalToSuperview().offset(14.auto())
            make.right.equalToSuperview().offset(-14.auto())
            make.height.equalTo(77.auto())
        }
        
        let var_one_v = ht_labelView("No ads to disturb.")
        var_contentView.addSubview(var_one_v)
        var_one_v.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(15.auto())
            make.bottom.equalTo(var_contentView.snp.centerY).offset(-5)
            make.height.equalTo(22.auto())
        }
        let var_two_v = ht_labelView("Unlock all premium features.")
        var_contentView.addSubview(var_two_v)
        var_two_v.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(15.auto())
            make.top.equalTo(var_contentView.snp.centerY).offset(5)
            make.height.equalTo(22.auto())
        }
        
        let var_saveBtn = UIButton()
        var_saveBtn.setTitle("PREMIUM", for: .normal)
        var_saveBtn.setTitleColor(.white, for: .normal)
        var_saveBtn.titleLabel?.font = .systemFont(ofSize: 20, weight: .bold)
        var_saveBtn.layer.cornerRadius = 10
        var_saveBtn.layer.masksToBounds = true
        var_saveBtn.onTap { [weak self] in
            self?.BLOCK_premiumBLOCK?()
        }
        contentView.addSubview(var_saveBtn)
        var_saveBtn.snp.makeConstraints { make in
            make.top.equalTo(var_contentView.snp.bottom).offset(30)
            make.centerX.equalToSuperview()
            make.width.equalTo(198)
            make.height.equalTo(44)
        }
        var_saveBtn.layoutIfNeeded()
        var_saveBtn.ht_setVerticalGradient(startColor: UIColor("#5CEBFD"), endColor: UIColor("#0691F3"))
       
        let var_termsOfUse = UIButton()
        var_termsOfUse.titleLabel?.font = .systemFont(ofSize: 14, weight: .medium)
        var_termsOfUse.setTitleColor(.white, for: .normal)
        var_termsOfUse.onTap {[weak self] in
            self?.BLOCK_webClickBLOCK?("https://www.baidu.com")
        }
        // 创建带有下划线的属性字符串
        let var_underlineAttribute = [NSAttributedString.Key.underlineStyle: NSUnderlineStyle.single.rawValue]
        let var_underlineAttributedString = NSAttributedString(string: "Terms of Use", attributes: var_underlineAttribute)
        var_termsOfUse.setAttributedTitle(var_underlineAttributedString, for: .normal)
        contentView.addSubview(var_termsOfUse)
        
        let var_privacyPolicy = UIButton()
        var_privacyPolicy.setTitleColor(.white, for: .normal)
        var_privacyPolicy.titleLabel?.font = .systemFont(ofSize: 14, weight: .medium)
        var_privacyPolicy.onTap {[weak self] in
            self?.BLOCK_webClickBLOCK?("https://www.baidu.com")
        }
        // 创建带有下划线的属性字符串
        let var_priva_underlineAttribute = [NSAttributedString.Key.underlineStyle: NSUnderlineStyle.single.rawValue]
        let var_priva_underlineAttributedString = NSAttributedString(string: "Privacy Policy", attributes: var_priva_underlineAttribute)
        var_privacyPolicy.setAttributedTitle(var_priva_underlineAttributedString, for: .normal)
        contentView.addSubview(var_privacyPolicy)
        
        let var_lin = UIButton()
        var_lin.backgroundColor = UIColor("#42444A")
        contentView.addSubview(var_lin)
        var_lin.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(var_saveBtn.snp.bottom).offset(30.auto())
            make.width.equalTo(1)
            make.height.equalTo(10.auto())
//            make.bottom.equalToSuperview().offset(-50)
        }
        var_termsOfUse.snp.makeConstraints { make in
            make.right.equalTo(var_lin.snp.left).offset(-15.auto())
            make.centerY.equalTo(var_lin.snp.centerY)
            
        }
        var_privacyPolicy.snp.makeConstraints { make in
            make.left.equalTo(var_lin.snp.right).offset(15.auto())
            make.centerY.equalTo(var_lin.snp.centerY)
        }
    }
    
    func ht_roundDot() -> UILabel {
        let var_label = UILabel()
        var_label.backgroundColor = UIColor("#1DCD00")
        var_label.layer.cornerRadius = 4.auto()
        var_label.layer.masksToBounds = true
        return var_label
    }
    
    func ht_labelView(_ var_text: String) -> UIView {
        let var_view = UIView()
        let var_roundDot = ht_roundDot()
        var_view.addSubview(var_roundDot)
        var_roundDot.snp.makeConstraints { make in
            make.left.equalToSuperview()
            make.centerY.equalToSuperview()
            make.width.height.equalTo(8.auto())
        }
        let var_label = UILabel()
        var_label.text = var_text
        var_label.textColor = .white
        var_label.font = .systemFont(ofSize: 16, weight: .medium)
        var_view.addSubview(var_label)
        var_label.snp.makeConstraints { make in
            make.left.equalTo(var_roundDot.snp.right).offset(5)
            make.centerY.equalToSuperview()
        }
        return var_view
    }
}
